package cn.zcx.servlet;

import com.wf.captcha.utils.CaptchaUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.01.25.21.09
 */
@WebServlet("/check")
public class Check extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<meta charset=\"utf-8\">");
        out.println("<title>玉灵 QQ:7031633 Email:webrx@126.com</title>");
        out.println("<meta name=\"keywords\" content=\"关键字\">");
        out.println("<meta name=\"description\" content=\"简介\">");
        out.println("</head>");
        out.println("<body>");

        //登录时检查验证码
        String c1 = req.getParameter("checkcode");
        if (c1 == null || "".equals(c1)) {
            out.print(String.format("<p style=color:red>验证码必须填写</p>"));
        } else if (CaptchaUtil.ver(c1, req)) {
            out.print(String.format("<p style=color:green>验证码正确</p>"));
            //在检查账号密码是不是正确
        } else {
            out.print(String.format("<p style=color:red>验证码填写错误</p>"));
        }

        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
